package com.zhonghan.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 项目路径拦截器
 * @author zhangceven
 *
 */
public class CommonInterceptor implements HandlerInterceptor {

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object obj, Exception e)
			throws Exception {
		

	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView e)
			throws Exception {
		

	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
		String path = request.getContextPath();
		String schema = request.getScheme();
		String serverName = request.getServerName();
		int port = request.getServerPort();
		String basePath = schema + "://" + serverName + ":" + port + path;
		request.setAttribute("basePath", basePath);
		
		return true;
	}

}
